package org.ipower.examsystem.dao.impl;

import org.ipower.examsystem.dao.ItemTopicsPropertiesDao;
import org.ipower.examsystem.dao.ItemTypesDao;
import org.ipower.examsystem.domain.ItemTopicsProperties;
import org.ipower.examsystem.domain.ItemTypes;
import org.ipower.examsystem.service.TopicProperty;

/**
 * 题干附加数据访问实现类。
 * @author young
 */
public class ItemTopicsPropertiesDaoImpl extends ModuleGenericDaoImpl<ItemTopicsProperties> implements ItemTopicsPropertiesDao {
    private ItemTypesDao typesDao = null;
    
    @Override
    public void setItemTypesDao(ItemTypesDao dao) {
        this.typesDao = dao;
    }
    
    @Override
    public TopicProperty loadProperties(String topicsID) {
        if(topicsID != null && !topicsID.isEmpty()){
           ItemTopicsProperties item = this.load(topicsID);
           if(item != null){
               TopicProperty data = new TopicProperty();
               data.setCatalogID(item.getCatalogID());
               data.setCheckCode(item.getCheckCode());
               data.setCreateTime(item.getCreateTime());
               data.setDifficulty(item.getDifficulty());
               data.setKeyword(item.getKeyword());
               data.setSectionID(item.getSectionID());
               data.setTypeID(item.getTypeID());
               if(this.typesDao != null){
                   ItemTypes type = this.typesDao.load(item.getTypeID());
                   if(type != null){
                       data.setTypeName(type.getTypeName());
                   }
               }
               return data;
           }
        }
        return null;
    }
}